<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.aux.lpeg_lexer</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_aux doc_spec_aux_lpeg_lexer_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../../'>Howl 0.3 Documentation</a></li><li>Spec</li><li>Aux</li><li>Spec - howl.aux.lpeg_lexer</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.aux.lpeg_lexer">howl.aux.lpeg_lexer</h1>&#x000A;&#x000A;<h4 id="the-module-can-be-called-directly-to-create-a-lexer-(same-as-new())">the module can be called directly to create a lexer (same as new())</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">not_has_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">l</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="the-resulting-lexer-can-be-called-directly">the resulting lexer can be called directly</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lexer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nc">P</span><span class="s1">'x'</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">lexer</span><span class="w"> </span><span class="s1">'x'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="imports-lpeg-definitions-locally-into-the-module">imports lpeg definitions locally into the module</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="k">for</span><span class="w"> </span><span class="n">op</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">{</span><span class="s1">'Cp'</span><span class="p">,</span><span class="w"> </span><span class="s1">'Ct'</span><span class="p">,</span><span class="w"> </span><span class="s1">'S'</span><span class="p">,</span><span class="w"> </span><span class="s1">'P'</span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">l</span><span class="p">[</span><span class="n">op</span><span class="p">]</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="imports-lpeg.locale-definitions-locally-into-the-module">imports lpeg.locale definitions locally into the module</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="k">for</span><span class="w"> </span><span class="n">ldef</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">{</span><span class="s1">'digit'</span><span class="p">,</span><span class="w"> </span><span class="s1">'upper'</span><span class="p">,</span><span class="w"> </span><span class="s1">'print'</span><span class="p">,</span><span class="w"> </span><span class="s1">'lower'</span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">l</span><span class="p">[</span><span class="n">ldef</span><span class="p">]</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="new">new<span class="arg-list">(definition)</span></h2>&#x000A;&#x000A;<h4 id="accepts-a-function">accepts a function</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">not_has_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="capture">capture<span class="arg-list">(style, pattern)</span></h2>&#x000A;&#x000A;<h4 id="returns-a-lpeg-pattern">returns a LPeg pattern</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'pattern'</span><span class="p">,</span><span class="w"> </span><span class="n">lpeg</span><span class="p">.</span><span class="n">type</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">capture</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="nc">P</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="the-returned-pattern-produces-the-three-captures-&lt;start-pos&gt;,-&lt;style-name&gt;-and-&lt;end-pos&gt;-if-&lt;pattern&gt;-matches">the returned pattern produces the three captures &lt;start-pos&gt;, &lt;style-name&gt; and &lt;end-pos&gt; if &lt;pattern&gt; matches</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">capture</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="nc">P</span><span class="s1">'fo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'foobar'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="predefined-helper-patterns">predefined helper patterns</h2>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=".eol">.eol</h3>&#x000A;&#x000A;<h4 id="matches-and-consumes-new-lines">matches and consumes new lines</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">eol</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'\n'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">eol</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'\r'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">eol</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'\n'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">eol</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'\r\n'</span><span class="w">&#x000A;&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">eol</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'a'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">eol</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'2'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=".float">.float</h3>&#x000A;&#x000A;<h4 id="matches-and-consumes-various-float-representations">matches and consumes various float representations</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="k">for</span><span class="w"> </span><span class="n">repr</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">{</span><span class="w"> </span><span class="s1">'34.5'</span><span class="p">,</span><span class="w"> </span><span class="s1">'3.45e2'</span><span class="p">,</span><span class="w"> </span><span class="s1">'1.234E1'</span><span class="p">,</span><span class="w"> </span><span class="s1">'3.45e-2'</span><span class="p">,</span><span class="w"> </span><span class="s1">'.32'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">float</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="n">repr</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=".hexadecimal">.hexadecimal</h3>&#x000A;&#x000A;<h4 id="matches-and-consumes-various-hexadecimal-representations">matches and consumes various hexadecimal representations</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="k">for</span><span class="w"> </span><span class="n">repr</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">{</span><span class="w"> </span><span class="s1">'0xfeab'</span><span class="p">,</span><span class="w"> </span><span class="s1">'0XDEADBEEF'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">hexadecimal</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="n">repr</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="does-not-match-illegal-hexadecimal-representations">does not match illegal hexadecimal representations</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">hexadecimal</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'0xCDEFG'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=".hexadecimal_float">.hexadecimal_float</h3>&#x000A;&#x000A;<h4 id="matches-and-consumes-various-hexadecimal-float-representations">matches and consumes various hexadecimal float representations</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="k">for</span><span class="w"> </span><span class="n">repr</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">{</span><span class="w"> </span><span class="s1">'0xfep2'</span><span class="p">,</span><span class="w"> </span><span class="s1">'0XAP-3'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">hexadecimal_float</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="n">repr</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="does-not-match-illegal-hexadecimal-representations">does not match illegal hexadecimal representations</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">hexadecimal_float</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'0xFGp3'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=".octal">.octal</h3>&#x000A;&#x000A;<h4 id="matches-and-consumes-octal-representations">matches and consumes octal representations</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">octal</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'0123'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="does-not-match-illegal-octal-representations">does not match illegal octal representations</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">octal</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'0128'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=".line_start">.line_start</h3>&#x000A;&#x000A;<h4 id="matches-after-newline-or-at-start-of-text">matches after newline or at start of text</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">line_start</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'x'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">eol</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">line_start</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">P</span><span class="s1">'x'</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'\nx'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="does-not-consume-anything">does not consume anything</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">eol</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">line_start</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'\nx'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="any">any<span class="arg-list">(list)</span></h2>&#x000A;&#x000A;<h4 id="the-resulting-pattern-is-an-ordered-match-of-any-member-of-&lt;list&gt;">the resulting pattern is an ordered match of any member of &lt;list&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">any</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'one'</span><span class="p">,</span><span class="w"> </span><span class="s1">'two'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'one'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'two'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'three'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="&lt;list&gt;-can-be-vararg-arguments">&lt;list&gt; can be vararg arguments</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">any</span><span class="w"> </span><span class="s1">'one'</span><span class="p">,</span><span class="w"> </span><span class="s1">'two'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'two'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="sequence">sequence<span class="arg-list">(list)</span></h2>&#x000A;&#x000A;<h4 id="the-resulting-pattern-is-a-chained-match-of-all-members-of-&lt;list&gt;">the resulting pattern is a chained match of all members of &lt;list&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">sequence</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'one'</span><span class="p">,</span><span class="w"> </span><span class="s1">'two'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'one'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'two'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'onetwo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'Xonetwo'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="&lt;list&gt;-can-be-vararg-arguments">&lt;list&gt; can be vararg arguments</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">sequence</span><span class="w"> </span><span class="s1">'one'</span><span class="p">,</span><span class="w"> </span><span class="s1">'two'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'onetwo'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="word">word<span class="arg-list">(list)</span></h2>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">grammar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">P</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="nc">V</span><span class="s1">'word'</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nc">P</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">V</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w">&#x000A;  </span><span class="ss">word:</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">word</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'one'</span><span class="p">,</span><span class="w"> </span><span class="s1">'two2'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="p">}</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-a-pattern-who-matches-any-word-in-&lt;list&gt;">returns a pattern who matches any word in &lt;list&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">grammar</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'one'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">grammar</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'so one match'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">grammar</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'!one'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">grammar</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'one()'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">grammar</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'then two2,'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">grammar</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'three'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="only-matches-standalone-words,-not-substring-occurences">only matches standalone words, not substring occurences</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">grammar</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'fone'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">grammar</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'one2'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">grammar</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'two2fold'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">grammar</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'two2_fold'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="accepts-var-arg-parameters">accepts var arg parameters</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">word</span><span class="p">(</span><span class="s1">'one'</span><span class="p">,</span><span class="w"> </span><span class="s1">'two'</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'two'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="span">span<span class="arg-list">(start_p, stop_p [, escape_p])</span></h2>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">span</span><span class="p">(</span><span class="s1">'{'</span><span class="p">,</span><span class="w"> </span><span class="s1">'}'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="matches-and-consumes-from-&lt;start_p&gt;-up-to-and-including-&lt;stop_p&gt;">matches and consumes from &lt;start_p&gt; up to and including &lt;stop_p&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'{}'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'{xx}'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="always-considers-&lt;eof&gt;-as-an-alternate-stop-marker">always considers &lt;EOF&gt; as an alternate stop marker</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'{x'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="allows-escaping-&lt;stop_p&gt;-with-&lt;escape_p&gt;">allows escaping &lt;stop_p&gt; with &lt;escape_p&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">span</span><span class="p">(</span><span class="s1">'{'</span><span class="p">,</span><span class="w"> </span><span class="s1">'}'</span><span class="p">,</span><span class="w"> </span><span class="s1">'\\'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'{\\}}'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="paired">paired<span class="arg-list">(p, escape [, pair_style, content_style])</span></h2>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">paired</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="matches-and-consumes-from-&lt;p&gt;-up-to-and-including-the-matching-&lt;p&gt;">matches and consumes from &lt;p&gt; up to and including the matching &lt;p&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'||x'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'|xx|x'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="always-considers-&lt;eof&gt;-as-an-alternate-stop-marker">always considers &lt;EOF&gt; as an alternate stop marker</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'|x'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="allows-escaping-the-end-delimiter-with-&lt;escape&gt;">allows escaping the end delimiter with &lt;escape&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">paired</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'\\'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'|\\|| foo\\'</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when pair_style and content_style are specified)</span></h3>&#x000A;&#x000A;<h4 id="captures-the-components-in-the-specified-styles">captures the components in the specified styles</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">paired</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="s1">'string'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">expected</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'string'</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w">&#x000A;</span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">expected</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'|foo|'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="still-handles-escapes-properly">still handles escapes properly</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">paired</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'%'</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="s1">'string'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">expected</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'string'</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w">&#x000A;</span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">expected</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'|f%|o|'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="back_was">back_was<span class="arg-list">(name, value)</span></h2>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Cg</span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">alpha</span><span class="o">^</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'group'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="s1">' '</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">back_was</span><span class="p">(</span><span class="s1">'group'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">)</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="matches-if-the-named-capture-&lt;named&gt;-previously-matched-&lt;value&gt;">matches if the named capture &lt;named&gt; previously matched &lt;value&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'foo '</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="does-not-match-if-the-named-capture-&lt;named&gt;-did-not-match-&lt;value&gt;">does not match if the named capture &lt;named&gt; did not match &lt;value&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'bar '</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="produces-no-captures">produces no captures</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'foo '</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="last_token_matches">last_token_matches<span class="arg-list">(pattern)</span></h2>&#x000A;&#x000A;<h4 id="matches-if-the-last-non-blank-token-matches-pattern">matches if the last non-blank token matches pattern</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">blank</span><span class="o">^</span><span class="mi">0</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">digit</span><span class="o">^</span><span class="mi">1</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">blank</span><span class="o">^</span><span class="mi">0</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">last_token_matches</span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">digit</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'123 '</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'123 \t '</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">' 123 '</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">' 1 '</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'1 '</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'1 '</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">' 1'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="match_back">match_back<span class="arg-list">(name)</span></h2>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Cg</span><span class="p">(</span><span class="nc">P</span><span class="s1">'x'</span><span class="p">,</span><span class="w"> </span><span class="s1">'start'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="s1">'y'</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">match_back</span><span class="p">(</span><span class="s1">'start'</span><span class="p">)</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="matches-the-named-capture-given-by-&lt;name&gt;">matches the named capture given by &lt;name&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xyxzx'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="produces-no-captures">produces no captures</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xyxzx'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="scan_until">scan_until<span class="arg-list">(stop_p [, escape_p])</span></h2>&#x000A;&#x000A;<h4 id="matches-until-the-specified-pattern-or-&lt;eof&gt;">matches until the specified pattern or &lt;EOF&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">scan_until</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'12x'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">scan_until</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'123'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="allows-escaping-&lt;stop_p&gt;-with-&lt;escape_p&gt;">allows escaping &lt;stop_p&gt; with &lt;escape_p&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">scan_until</span><span class="p">(</span><span class="s1">'}'</span><span class="p">,</span><span class="w"> </span><span class="s1">'\\'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'{\\}}'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="scan_to">scan_to<span class="arg-list">(stop_p [, escape_p])</span></h2>&#x000A;&#x000A;<h4 id="matches-until-the-specified-pattern-or-&lt;eof&gt;">matches until the specified pattern or &lt;EOF&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">scan_to</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'12x'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">scan_to</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'123'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="allows-escaping-&lt;stop_p&gt;-with-&lt;escape_p&gt;">allows escaping &lt;stop_p&gt; with &lt;escape_p&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">scan_to</span><span class="p">(</span><span class="s1">'}'</span><span class="p">,</span><span class="w"> </span><span class="s1">'\\'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'{\\}}'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="scan_through_indented">scan_through_indented</h2>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">P</span><span class="s1">' '</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">scan_through_indented</span><span class="o">!</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="matches-until-the-indentation-is-smaller-or-equal-to-the-current-line">matches until the indentation is smaller or equal to the current line</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">' x\n y'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">8</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">' x\n  y\n z'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="matches-until-eol-if-it-can-not-find-any-line-with-smaller-or-equal-indentation">matches until eol if it can not find any line with smaller or equal indentation</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">' x\n  y'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="uses-the-indentation-of-the-line-containing-eol-if-positioned-right-at-it">uses the indentation of the line containing eol if positioned right at it</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">eol</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">scan_through_indented</span><span class="o">!</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">8</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">' x\n  y\n z'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="scan_until_capture">scan_until_capture<span class="arg-list">(name, escape, [, halt_at, halt_at_N, ..])</span></h2>&#x000A;&#x000A;<h4 id="matches-until-the-named-capture">matches until the named capture</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Cg</span><span class="p">(</span><span class="s1">'x'</span><span class="p">,</span><span class="w"> </span><span class="s1">'start'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">scan_until_capture</span><span class="p">(</span><span class="s1">'start'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xyzx'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="stops-matching-at-any-optional-halt_at-parameters">stops matching at any optional halt_at parameters</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Cg</span><span class="p">(</span><span class="s1">'x'</span><span class="p">,</span><span class="w"> </span><span class="s1">'start'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">scan_until_capture</span><span class="p">(</span><span class="s1">'start'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="s1">'z'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xyzx'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="treats-all-stop-parameters-as-strings-and-not-patterns">treats all stop parameters as strings and not patterns</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Cg</span><span class="p">(</span><span class="s1">'x'</span><span class="p">,</span><span class="w"> </span><span class="s1">'start'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">scan_until_capture</span><span class="p">(</span><span class="s1">'start'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="s1">'%w'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xyz%w'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="does-not-halt-on-escaped-matches">does not halt on escaped matches</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Cg</span><span class="p">(</span><span class="s1">'x'</span><span class="p">,</span><span class="w"> </span><span class="s1">'start'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">scan_until_capture</span><span class="p">(</span><span class="s1">'start'</span><span class="p">,</span><span class="w"> </span><span class="s1">'\\'</span><span class="p">,</span><span class="w"> </span><span class="s1">'z'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xy\\x\\zx'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="matches-until-eof-if-no-match-is-found">matches until eof if no match is found</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Cg</span><span class="p">(</span><span class="s1">'x'</span><span class="p">,</span><span class="w"> </span><span class="s1">'start'</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">scan_until_capture</span><span class="p">(</span><span class="s1">'start'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xyz'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="match_until">match_until<span class="arg-list">(stop_p, p)</span></h2>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">match_until</span><span class="p">(</span><span class="s1">'\n'</span><span class="p">,</span><span class="w"> </span><span class="nc">C</span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">alpha</span><span class="p">))</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="matches-p-until-stop_p-matches">matches p until stop_p matches</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'x'</span><span class="p">,</span><span class="w"> </span><span class="s1">'y'</span><span class="p">,</span><span class="w"> </span><span class="s1">'z'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xyz\nx'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="matches-until-eof-if-stop_p-is-not-found">matches until eof if stop_p is not found</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'x'</span><span class="p">,</span><span class="w"> </span><span class="s1">'y'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xy'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="complement">complement<span class="arg-list">(p)</span></h2>&#x000A;&#x000A;<h4 id="matches-if-&lt;p&gt;-does-not-match">matches if &lt;p&gt; does not match</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">complement</span><span class="p">(</span><span class="s1">'a'</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'b'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">complement</span><span class="p">(</span><span class="s1">'a'</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'a'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">complement</span><span class="p">(</span><span class="s1">'a'</span><span class="p">)</span><span class="o">^</span><span class="mi">1</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nc">Cp</span><span class="o">!</span><span class="p">)</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'bca'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="sub_lex_by_pattern">sub_lex_by_pattern<span class="arg-list">(mode_p, mode_style, stop_p)</span></h2>&#x000A;&#x000A;<h4 id="lexes-any-leading-space-followed-by-eol-as-extended-whitespace">lexes any leading space followed by eol as extended whitespace</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">sub_lex_by_pattern</span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">alpha</span><span class="o">^</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="s1">'&gt;'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xx \n123&gt;'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">'default:whitespace'</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="s1">'embedded'</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="w">&#x000A;</span><span class="p">},</span><span class="w"> </span><span class="n">res</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when no mode is found for the &lt;mode_p&gt; capture)</span></h3>&#x000A;&#x000A;<h4 id="emits-mode-match-styling-and-an-embedded-capture-for-the-sub-text">emits mode match styling and an embedded capture for the sub text</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">sub_lex_by_pattern</span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">alpha</span><span class="o">^</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="s1">'&gt;'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xx123&gt;'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">'embedded'</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;</span><span class="p">},</span><span class="w"> </span><span class="n">res</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when a mode matching the &lt;mode_p&gt; capture exists)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">p</span><span class="w">&#x000A;&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">sub_mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">lexer:</span><span class="w"> </span><span class="n">l</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">capture</span><span class="p">(</span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="n">digit</span><span class="o">^</span><span class="mi">1</span><span class="p">)</span><span class="w">&#x000A;  </span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'dynsub'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">sub_mode</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">P</span><span class="s1">'&lt;'</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">sub_lex_by_pattern</span><span class="p">(</span><span class="n">l</span><span class="p">.</span><span class="n">alpha</span><span class="o">^</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="s1">'&gt;'</span><span class="p">)</span><span class="w">&#x000A;&#x000A;</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'dynsub'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="emits-mode-match-styling-and-rebasing-instructions-to-the-styler">emits mode match styling and rebasing instructions to the styler</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="mi">8</span><span class="p">,</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="s1">'dynsub|embedded'</span><span class="w">&#x000A;</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'&lt;dynsub&gt;'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="lexes-the-content-using-that-mode's-lexer-until-&lt;stop_p&gt;">lexes the content using that mode's lexer until &lt;stop_p&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="mi">8</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'dynsub|embedded'</span><span class="w">&#x000A;</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'&lt;dynsub123&gt;'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="sub_lex">sub_lex<span class="arg-list">(mode_name, stop_p)</span></h2>&#x000A;&#x000A;<h4 id="lexes-any-leading-space-followed-by-eol-as-extended-whitespace">lexes any leading space followed by eol as extended whitespace</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">sub_lex</span><span class="p">(</span><span class="s1">'unknown'</span><span class="p">,</span><span class="w"> </span><span class="s1">'&gt;'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">' \n123&gt;'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'default:whitespace'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">'embedded'</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;</span><span class="p">},</span><span class="w"> </span><span class="n">res</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when no mode is found matching &lt;mode_name&gt;)</span></h3>&#x000A;&#x000A;<h4 id="captures-using-the-embedded-style-until-stop_p">captures using the embedded style until stop_p</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">sub_lex</span><span class="p">(</span><span class="s1">'unknown'</span><span class="p">,</span><span class="w"> </span><span class="s1">'&gt;'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'xx&gt;'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'embedded'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">},</span><span class="w"> </span><span class="n">res</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when a mode matching &lt;mode_name&gt; exists)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">p</span><span class="w">&#x000A;&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">sub_mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">lexer:</span><span class="w"> </span><span class="n">l</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">capture</span><span class="p">(</span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="n">digit</span><span class="o">^</span><span class="mi">1</span><span class="p">)</span><span class="w">&#x000A;  </span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'sub'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">sub_mode</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">sub_lex</span><span class="p">(</span><span class="s1">'sub'</span><span class="p">,</span><span class="w"> </span><span class="s1">'&gt;'</span><span class="p">)</span><span class="w">&#x000A;&#x000A;</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'sub'</span><span class="w">&#x000A;&#x000A;</span><span class="n">sub_captures_for</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">text</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="n">text</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">res</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="emits-rebasing-instructions-to-the-styler">emits rebasing instructions to the styler</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="s1">'sub|embedded'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">''</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="lexes-the-content-using-that-mode's-lexer-until-&lt;stop_p&gt;">lexes the content using that mode's lexer until &lt;stop_p&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">},</span><span class="w"> </span><span class="n">sub_captures_for</span><span class="w"> </span><span class="s1">'12&gt;'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="lexes-until-eof-if-&lt;stop_p&gt;-is-not-found">lexes until EOF if &lt;stop_p&gt; is not found</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">},</span><span class="w"> </span><span class="n">sub_captures_for</span><span class="w"> </span><span class="s1">'12'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="compose">compose<span class="arg-list">(base_mode, pattern)</span></h2>&#x000A;&#x000A;<h4 id="returns-a-conjunction-pattern-with-&lt;pattern&gt;-and-the-mode-pattern">returns a conjunction pattern with &lt;pattern&gt; and the mode pattern</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">base_mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">lexer:</span><span class="w"> </span><span class="n">l</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">capture</span><span class="p">(</span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="n">digit</span><span class="o">^</span><span class="mi">1</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'base_mode'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">base_mode</span><span class="w">&#x000A;</span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">compose</span><span class="p">(</span><span class="s1">'base_mode'</span><span class="p">,</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">capture</span><span class="p">(</span><span class="s1">'override'</span><span class="p">,</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">alpha</span><span class="p">))</span><span class="o">^</span><span class="mi">0</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'override'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w">&#x000A;  </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w">&#x000A;</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">p</span><span class="o">\</span><span class="n">match</span><span class="w"> </span><span class="s1">'a2'</span><span class="w"> </span><span class="p">}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="built-in-lexing-support">built-in lexing support</h2>&#x000A;&#x000A;<h4 id="automatically-lexes-whitespace">automatically lexes whitespace</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lexer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nc">P</span><span class="s1">'peace-and-quiet'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'whitespace'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">lexer</span><span class="w"> </span><span class="s1">' \n'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="automatically-skips-non-recognized-tokens">automatically skips non-recognized tokens</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lexer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">capture</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="nc">P</span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">lexer</span><span class="w"> </span><span class="s1">'|foo'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2015
            <a class='alert-link' href='https://github.com/nilnor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
